package com.xujianjie.orderservice.controller;

import com.xujianjie.orderservice.model.Order;
import com.xujianjie.orderservice.model.ResponseData;
import com.xujianjie.orderservice.service.OrderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/order")
public class OrderController
{
    @Autowired
    private OrderService orderService;

    @RequestMapping(value = "/create", method = RequestMethod.GET)
    public ResponseData createOrder(Integer userId, Integer goodsId, Integer count)
    {
        orderService.createOrder(userId, goodsId, count);
        return new ResponseData(ResponseData.STATUS_FAILED, null, "下单成功！");
    }

    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public ResponseData info(Integer goodsId)
    {
        Order order = orderService.findById(goodsId);
        if (order != null)
        {
            return new ResponseData(ResponseData.STATUS_OK, order, "获取成功！");
        }
        else
        {
            return new ResponseData(ResponseData.STATUS_FAILED, null, "获取失败！");
        }
    }
}
